﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyHealthByDesignWebsite.Models
{
    public class FoodDesc
    {
        private FullDataSetDataContext db = new FullDataSetDataContext();
        //

        public IEnumerable<int> NDB_No { get; set; }

        
        public MultiSelectList Long_Desc { get; set; }


        /// <summary>
        /// Gets the list of FOOD_DES records which has the SearchText
        /// </summary>
        /// <param name="searchText"></param>
        /// <returns></returns>
        public IQueryable<FOOD_DE> FoodDescByText(string searchText)
        {
            return from m in db.FOOD_DEs
                   where m.Long_Desc.Contains(searchText)
                   select m;
            
        }

        /// <summary>
        /// Gets the 'Long_Desc' value for a given 'NDB_No'
        /// </summary>
        /// <param name="NDBno"></param>
        /// <returns></returns>
        public string FoodDescByNDBNo(string NDBno)
        {
            string longDesc;
            IQueryable<string> foodDesc= from m in db.FOOD_DEs where m.NDB_No.Equals(NDBno) select m.Long_Desc;
            longDesc=foodDesc.First();
            return longDesc;

        }

       
        //
        // Persistence
        public void Save()
        {

            db.SubmitChanges();

        }    
    
    }
}